package com.tgy.JUC.StreamTest;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

/***
 * @ClassName: StreamDemo
 * @Description: stream 试用'
 * id是偶数
 * 年龄大于23
 * 用户名转大写
 * 排序字母倒排
 * 只输出一个用户
 * @Auther: 送你一块二向箔
 * @Date: 16:42 2022/3/14
 * @version : V1.0
 */
public class StreamDemo {
    public static void main(String[] args) {
        run1();

    }

    public static void run1() {
        User u1 = new User(1, "a", 21);
        User u2 = new User(2, "b", 22);
        User u3 = new User(3, "c", 23);
        User u4 = new User(4, "d", 24);
        User u5 = new User(5, "e", 25);
        List<User> users = Arrays.asList(u1, u2, u3, u4, u5);
        users.stream()
                .filter((o) -> { return o.getAge() > 21; })
                .filter((o) -> { return o.getId() % 2 == 0; })
                .map((o)->{o.setName(o.getName().toUpperCase(Locale.ROOT));return o;})
                .sorted((Comparator.comparing(User::getName)).reversed())
                .limit(1)
                .forEach(System.out::println);
    }
}
